<template>
	<z-paging ref="paging" v-model="dataList" @query="queryList"
		:loading-more-custom-style="{ paddingBottom: 'env(safe-area-inset-bottom)' }">
		<template #top>
			<view class="zpagin_top">
				<nav-bar :iconLeft="true" />
				<view class="search">
					<custom-search v-model="queryParams.search" @search="refreshList" placeholder="请输入货品名称" />
					<uni-data-select style="z-index: 50;" placeholder="请选择仓库" v-model="queryParams.stock_control__warehouse__id"
						:localdata="warehouse_list" @change="refreshList" />
				</view>
			</view>
		</template>
		<uni-card v-for="item in dataList" :key="item.id" :title="item.s_name" :sub-title="item.s_code" margin="10px"
			spacing="0">
			<view class="ctent">规格：{{ item.s_specification }}</view>
			<view class="ctent">上期剩余库存：{{ item.up_num_info }}</view>
			<view class="con" style="align-items: normal;">
				<view class="ctent" style="flex: none;">当前操作库存：</view>
				<view class="ctent">
					<view class="con">
						<up-icon :name="item.change_type == 1 ? 'plus' : 'minus'" :color="item.change_type == 1 ? 'green' : 'red'"
							size="16" style="display: inline-block;" />
						{{ item.change_num_info }}
					</view>
				</view>
			</view>
			<view class="con">
				<view class="ctent">剩余库存：{{ item.all_num_info }}</view>
				<view class="ctent">仓库名称：{{ item.warehouse_name }}</view>
			</view>
			<view class="con">
				<view class="ctent">类型：{{ item.classify_display }}</view>
				<view class="ctent">操作人：{{ item.create_full_name }}</view>
			</view>
			<view class="ctent">操作时间：{{ item.create_date }}</view>
			<view class="ctent">备注：{{ item.desc }}</view>

		</uni-card>
	</z-paging>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import wareDetailApi from '../../../api/warehouse/ware_detail'

onLoad(() => {
	get_warehouse_list()
})

//数据请求
const paging = ref(null);
const dataList = ref([]);
const queryParams = reactive({
	search: '',
	stock_control__warehouse__id: ''
})
function queryList(pageNo, pageSize) {
	const params = {
		page: pageNo,
		page_size: pageSize,
		...queryParams
	}
	wareDetailApi.get_stock_control_change(params).then((res) => {
		paging.value.complete(res.results);
	})
}
const warehouse_list = ref([])
function get_warehouse_list() {
	const params = { page: 1, page_size: 99999, if_open: 1 };
	wareDetailApi.get_warehouse(params).then(res => {
		warehouse_list.value = res.results.map(v => ({
			text: v.name,
			value: v.id
		}))
	})
}
function refreshList() {
	paging.value.reload();
}
</script>

<style lang="scss"></style>